<template>
    <div id="share">
        <van-nav-bar title="邀请好友" left-text="返回" left-arrow @click-left="$router.go(-1)" />
        <br />
      <van-cell-group inset>
        <div class="qrcode" ref="url"></div>
      </van-cell-group>
    </div>
</template>

<script>
import QRCode from 'qrcodejs2'

export default {
    name: "Share",
    components: {
        QRCode
    },
    methods: {
        load() {
            this.$requests.post('/user/info/obtain').then(resp=>{
                let size = document.body.clientWidth / 2
                new QRCode(this.$refs.url, {
                    text: `${window.location.origin}/register?parent_hex_id=${resp.hex_id}`,
                    correctLevel: QRCode.CorrectLevel.H,
                    colorLight: '#ffffff',
                    colorDark: '#000000',
                    height: size,
                    width: size
                })
            })
        }
    },
    mounted() {
        this.load()
    }
}
</script>

<style scoped>
.qrcode {
    width: 50%;
    margin: 40% auto;
}
</style>
